<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
$admin = new admin();
$admin->canView($_SERVER['PHP_SELF']);
$name=$_GET['group'];
$gid=$_GET['gid'];
$data=new database();
$data->db(DATABASE)->collection('admin_pages');
$data->criteria(array('role'=>'functionality'))->sort(array('name'=>1));
$rows=$data->findNl();
$data->close();
// now what - can edit pages and shit ?
echo('<form class="inline" action="/admin/resources/php/requests/actions/save-group.php">
<input type="hidden" class="settings" value=\'{"buttonWaitingValue":"Saving","updateNode":"#response"}\' />	
');
echo('<input type="hidden" name="group_name" value="'.$name.'" />');
echo('<input type="hidden" name="group_id" value="'.$gid.'" />');

echo('<input type="submit" class="button" value="Update group settings" style="float:right;" />');
echo('<h1 style="margin-bottom:1em;">Editing group access controls for '.$name.'</h1>');
echo('<div class="form-field" style="height:200px;overflow-x:hidden;overflow-y:auto;width:510px;float:left;">');
echo('<h2 class="form-heading">Administration functions / access control</h2>');

echo('<ul>');

foreach($rows['results'] as $row) {
	$checked=(in_array($name,$row['groups'])) ? ' checked="checked"' : '';
	echo('<li><input type="checkbox"'.$checked.' name="group_functionality[]" value="'.$row['path'].'" /><strong>'.$row['name'].'</strong></li>');	
}
echo('</ul>');
echo('</div>');
echo('<div class="form-field" style="height:200px;overflow-x:hidden;overflow-y:auto;width:510px;float:left;margin-left:2em;">');
echo('<h2 class="form-heading">Content page by page access control (editing)</h2>');
echo('<p class="hint">If no groups are checked only Administrators can edit pages </p>');
echo('<p class="hint">Make sure the functions of edit page and save page are also ticked </p>');

$name=$_GET['group'];
$data=new database();
$data->db(DATABASE)->collection('admin_pages');
$data->criteria(array('role'=>'page'))->sort(array('name'=>1));
$admin_pages=$data->findNl();
$data->close();
foreach($admin_pages['results'] as $row) {
	
	$o[]=$row['path'];	
}
//print_r($o);
$data=new database();
$data->db(DATABASE)->collection('pages');
$data->criteria(array('text'=>array('$exists'=>true)));
$pages=$data->findNl();
$data->close();

echo('<ul>');
foreach($pages['results'] as $row) {
// url is in
$checked=(in_array($row['url'],$o)) ? ' checked="checked"' : ''; 	
echo('<li><input type="checkbox" name="group_page['.$row['url'].']" value="'.$row['text'].'"'.$checked.' /> <strong>'.$row['text'].'</strong> ('.$row['url'].')</li>');

}
echo('</ul>');
echo('</div>');
echo('<div class="clearfix" style="margin-top:2em;margin-bottom:2em;"></div>');
echo('</form>');
?>
<br /><br />
